<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Model;
use util\Tree;

/**
 * 服务管理
 * @package app\erp\model
 */
class ErpService extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_service';

    // 定义全局的查询范围
    protected function base($query)
    {
        $query->where('service_status', 0);
    }

    /**
     * 添加数据
     * @param service_name 	string 服务名称
     * @param service_classid  int 服务分类id
     * @param price 	    string 价格
     * @author jason
     * @return array_out(code, message, (int)id)
     */
    public function addData($service_name, $price, $service_classid, $description, $store_id, $mobile){
        $data['service_name']       = $service_name;
        $data['service_classid']    = $service_classid;
        $data['price']             	= $price;
        $data['description']        = $description;
        $data['store_id']           = $store_id;
        $data['mobile']           	= $mobile;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success', $this->id);
        }else{
            return array_out(-1001, 'error');
        }
    }

    /**
     * 编辑数据
     * @param service_name 	string 服务名称
     * @param service_classid  int 服务分类id
     * @param price 	    string 价格
     * @author jason
     * @return array_out(code, message, (int)id)
     */
    public function editData($service_id, $service_name, $price, $service_classid, $description, $store_id, $mobile){
        $map = [];
        $map['id'] = $service_id;

        $data = [];
        $data['service_name']         = $service_name;
        $data['service_classid']      = $service_classid;
        $data['price']                = $price;
        $data['description']          = $description;
        $data['store_id']             = $store_id;
        $data['mobile']               = $mobile;
        $res = $this ->update($data, $map);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
